using System;
using System.Collections.Generic;
using System.Text;
using Objects;
namespace DAL
{
    public class DALChiNhanh
    {

        public List<ChiNhanh> GetAllItem()
        {
            List<ChiNhanh> ListChiNhanh = new List<ChiNhanh>();

            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] {  };
            string[] vname = new string[] {  };
            System.Data.DataSet ds = acc.CommandSelect("ChiNhanh_GetAllItem", sname, vname);
            ChiNhanh Item = new ChiNhanh();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                System.Data.DataRow dr = ds.Tables[0].Rows[i];
                ListChiNhanh.Add((Item.Populate(dr)));
            }
            return ListChiNhanh;
        }

        public List<ChiNhanh> GetByIdTinhThanh(int IdTinhThanh)
        {
            List<ChiNhanh> ListChiNhanh = new List<ChiNhanh>();

            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@IdTinhThanh", "@Status" };
            string[] vname = new string[] {IdTinhThanh.ToString(), Common.Myconst.HOATDONG.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("ChiNhanh_GetByIdTinhThanh", sname, vname);
            ChiNhanh Item = new ChiNhanh();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                System.Data.DataRow dr = ds.Tables[0].Rows[i];
                ListChiNhanh.Add((Item.Populate(dr)));
            }
            return ListChiNhanh;
        }

        public List<ChiNhanh> GetByTenChiNhanh(String ten)
        {
            List<ChiNhanh> ListChiNhanh = new List<ChiNhanh>();

            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Ten","@Status" };
            string[] vname = new string[] { ten.ToString(),Common.Myconst.HOATDONG.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("ChiNhanh_GetbyTenChiNhanh", sname, vname);
            ChiNhanh Item = new ChiNhanh();
            
          
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                System.Data.DataRow dr = ds.Tables[0].Rows[i];
                ListChiNhanh.Add((Item.Populate(dr)));
            }
            return ListChiNhanh;
        }

        public ChiNhanh GetById(int Id)
        {
            clsDataAccess acc = new clsDataAccess();
            string[] sname = new string[] { "Status", "@Id" };
            string[] vname = new string[] { Common.Myconst.HOATDONG.ToString(), Id.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("ChiNhanh_GetById", sname, vname);
            ChiNhanh Item = new ChiNhanh();

            System.Data.DataRow dr = ds.Tables[0].Rows[0];
            return Item.Populate(dr);
        }

        public int Insert_ChiNhanh(String TenChiNhanh, String DiaChi, String SoDienThoai, int IdTinhThanh, int SapXep)
        {
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Ten","@DiaChi","@SoDienThoai","@IdTinhThanh","@Status","@SapXep" };
            string[] vname = new string[] { TenChiNhanh.ToString(), DiaChi.ToString(), SoDienThoai.ToString(), IdTinhThanh.ToString(), Common.Myconst.HOATDONG.ToString(), SapXep.ToString() };
            return acc.InsertUpdateDetete("Chinhanh_Insert", sname, vname);
        
        }

        public int Update_ChiNhanh(int idchinhanh, String TenChiNhanh, String DiaChi, String SoDienThoai, int IdTinhThanh, int Status, int SapXep)
        {
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Id", "@Ten", "@DiaChi", "@SoDienThoai", "@IdTinhThanh", "@Status", "@SapXep" };
            string[] vname = new string[] { idchinhanh.ToString(), TenChiNhanh.ToString(), DiaChi.ToString(), SoDienThoai.ToString(), IdTinhThanh.ToString(), Status.ToString(), SapXep.ToString() };
            return acc.InsertUpdateDetete("ChiNhanh_Update", sname, vname);

        }

        public int Delete_ChiNhanh(int idchinhanh)
        {
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Id" };
            string[] vname = new string[] { idchinhanh.ToString()};
            return acc.InsertUpdateDetete("ChiNhanh_Delete", sname, vname);

        }

    }
}
